/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utilidades;

import java.awt.Color;
import java.awt.event.KeyEvent;
import javax.swing.JProgressBar;
import javax.swing.JTextField;
import net.java.balloontip.BalloonTip;
import net.java.balloontip.styles.BalloonTipStyle;
import net.java.balloontip.styles.MinimalBalloonStyle;

/**
 *
 * @author Lelouch
 */
public class ValidaUF extends ValidaDecimal {
	JProgressBar pb;
	JTextField tf;
	boolean usado;
	BalloonTip bt;

	public JProgressBar getPb () {
		return this.pb;
	}

	public ValidaUF (JTextField tf, JProgressBar pb) {
		usado = false;
		this.pb = pb;
		this.tf = tf;
		bt = new BalloonTip (tf, "", new MinimalBalloonStyle (new Color (231, 225, 165), 2),
			BalloonTip.Orientation.LEFT_ABOVE, BalloonTip.AttachLocation.ALIGNED, 20, 10, false);
		bt.setVisible (false);
	}

	@Override
	public void keyTyped (KeyEvent e) {
		if (!tf.getText().equals ("") && !usado) {
			usado = true;
		}
		bt.setVisible (false);
		char caracter = e.getKeyChar ();
		if ((caracter >= '0' && caracter <= '9') || caracter == '.') {
			String concat = concat = tf.getText () + caracter;	// Se concatena el TextField con la letra ingresada
			if (concat.matches ("[0-9]*\\.{0,1}[0-9]*")) {
				if (!usado) {
					pb.setValue (pb.getValue () + 1);
					usado = true;
				}
			}
			else {
				if (caracter == '.') {
					bt.setText ("Ya existe un punto decimal");
					bt.setVisible (true);
				}
				e.consume ();
			}
		} else if (e.getKeyChar () == KeyEvent.VK_BACK_SPACE || e.getKeyChar () == KeyEvent.VK_DELETE) {
			if (tf.getText().equals ("") && usado) {
				pb.setValue (pb.getValue () - 1);
				usado = false;
			}
		}
		else {
			bt.setText ("Ingrese sólo valores monetarios");
			bt.setVisible (true);
			e.consume ();
		}
	}

}



